import time
import uuid
import xlrd
import jwt
from django.core.cache import cache
from django.core.validators import EmailValidator, int_list_validator, MaxLengthValidator
from django.test import TestCase

# Create your tests here.
from django.utils import timezone
from werkzeug.security import generate_password_hash, check_password_hash

from common.utils.jwt_utils import AuthJwt
from common.utils.other_utils import get_random_secret_key
from common.validate import validate_phone
from extends.microseer.login.login import moa_login
from platform_auth import settings


class PersonTest(TestCase):

    def test_01(self):
        import os

        for i, v in enumerate(os.environ.items(), 1):
            print(i, v)

        print(os.environ.get('PLATFORM'))

    def test_02(self):
        print(generate_password_hash('123456')[0])

        print(check_password_hash(
            'pbkdf2:sha256:260000$9J60jfZT2WBvgc4e$a36f151f27fd288904509389ba5664fe1c4d4ec4ff06b942f9a1cf8aa1a280ef',
            '123456'))

    def test_03(self):
        print(settings.JWT_EXPIRATION_DELTA.strftime('%Y-%m-%d %H:%M:%S'))

    def test_04(self):
        token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzgzNjQyMjAsImlkIjoxLCJ1c2VybmFtZSI6ImFkbWluIiwiZXhwaXJlX3RpbWUiOiIyMDIxLTEyLTAxIDEzOjEwOjIwIn0.PRFstjqi1RSA-2lTCtj-eJOEs6fwMd7b3QVXLF2sa9E2'
        print(cache.get(f'PLATFORM_AUTH.{token}'))

    def test_token(self):
        import jwt

        token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDAxMDU2NjQsImlhdCI6MTY0MDAxOTI2NiwiaWQiOjQsInVzZXJuYW1lIjoiYWRtaW4ifQ.DXK5xMDX9_iKsQofYBTKHuP_YXmLuV992G9Z9nWMmwo'

        secret = 'n8h($(a!(82rf8@69q9*8m!l6r0j(8(sxib@&v+50r$@lk8jkp'

        print(jwt.decode(jwt = token.encode('GBK'), key = secret, algorithms = ['HS256']))

    def test_08(self):
        private_key = get_random_secret_key()
        print(private_key)
        encoded = jwt.encode({"some": "payload"}, private_key, algorithm = "HS256")
        print(encoded)
        decoded = jwt.decode(encoded, private_key, algorithms = ["HS256"])
        print(decoded)

    def test_09(self):
        persons = ''

        print(str(persons).split(','))

    def test_10(self):

        # moa_login(env = 'pres')
        personIds = [1, 2, 3]
        personId = [1, 2, 3]

        if not isinstance(personIds, list):
            print('参数异常')

        print(tuple(personIds))

        print(list(set(personIds).difference(set(personId))))

    def test_11(self):

        pass